<?php

class Default_Form_ChangePassword extends Zend_Form {
	const OLD_PASSWORD_LABEL     = 'Mật khẩu hiện tại';
	const NEW_PASSWORD_LABEL     = 'Mật khẩu mới';
	const CONFIRM_PASSWORD_LABEL = 'Xác nhận lại mật khẩu';
	const PASSWORD_MIN_LENGTH    = 6;
	const PASSWORD_MAX_LENGTH    = 32;
	const ENCODING               = 'UTF-8';

	public function init() {

		$this->setName('frmChangePass');
		//Not empty validate
		$passwordNotEmpty = new Zend_Validate_NotEmpty();
		//Length validate
		$passwordLength = new Zend_Validate_StringLength(self::PASSWORD_MIN_LENGTH, self::PASSWORD_MAX_LENGTH, self::ENCODING);
		$oldpassword = new Zend_Form_Element_Password('oldpassword');
		$oldpassword->setLabel(self::OLD_PASSWORD_LABEL)
					->addFilter('StringTrim')
					->setAttrib('value', null)
					->setRequired(true)
					->addValidator($passwordNotEmpty, true)
					->addValidator($passwordLength);
			
		$newpassword = new Zend_Form_Element_Password('newpassword');
		$newpassword->setLabel(self::NEW_PASSWORD_LABEL)
					->addFilter('StripTags')
					->addFilter('StringTrim')
					->setAttrib('value', null)
					->setRequired(true)
					->addValidator($passwordNotEmpty, true)
					->addValidator($passwordLength);
					
		$confirmpassword = new Zend_Form_Element_Password('cfrmpassword');
    	$confirmpassword->setLabel(self::CONFIRM_PASSWORD_LABEL)
						->addFilter('StripTags')
						->addFilter('StringTrim')
            			->setRequired(true)
						->addValidator($passwordNotEmpty, true)
            			->addValidator($passwordLength)
            			->addValidator('Identical', false, array('token' => 'newpassword'));
				
		$this->addElements(array($oldpassword, $newpassword, $confirmpassword));
	}
}
